package com.ousi.wx.controller;

import cn.hutool.core.bean.BeanUtil;
import com.ousi.wx.common.CommonResult;
import com.ousi.wx.controller.form.SelectVarietiesByPageForm;
import com.ousi.wx.service.LotusVarietiesService;
import com.ousi.wx.util.PageUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

@RequestMapping("/lotus/varieties")
@RestController
@Slf4j
@Tag(name = "LotusVarietiesController", description = "品种对比表信息管理接口")
public class LotusVarietiesController {

    @Autowired
    private LotusVarietiesService lotusVarietiesService;

    @PostMapping("/selectAll")
    @Operation(summary = "分页显示品种对比信息接口")
    public CommonResult selectAll(@RequestBody @Valid SelectVarietiesByPageForm form) {
        Map param = BeanUtil.beanToMap(form);
        int page = form.getPage();
        int length = 20;
        int start = (page - 1) * length;
        param.put("start", start);
        param.put("length", length);
        PageUtils pageUtils = lotusVarietiesService.selectAll(param);
        return CommonResult.ok().put("result", pageUtils);
    }
}
